import steer
import vector
import random


class Wander (steer.Steer):
    
    targetCircle = vector.Vector(0,0)
    __wanderRadius__ = 10.0
    wanderDistance = 2.0
    randomDisplacement = 1.2
    

    def __init__(self, position = vector.Vector(0.0,0.0), orientation = vector.Vector(0.0,0.0), velocity = vector.Vector(0.0,0.0) ):
        steer.Steer.__init__(self)
        self.position = position
        self.orientation = orientation
        self.velocity = velocity
        self.targetCircle = self.velocity.normalize().multiple(self.__wanderRadius__/2.0)
    
    def calculate(self):
        random.seed(None)
        #przesuwamy okrag celu o malutki wektor pomnozony przez randomDisplacement
        self.targetCircle = self.targetCircle.add(vector.Vector( random.random()*2.0 - 1.0, random.random()*2.0 - 1.0 ).multiple(self.randomDisplacement) ) 
        
        #normalizujemy wektor polozenia okregu celu i mnozymy przez promien duzego okregu
        #w rezultacie rzutujemy okrag celu spowtorem na duzy okrag
        
        self.targetCircle = self.targetCircle.normalize().multiple(self.__wanderRadius__)
        
        desiredVelocity = self.targetCircle.add(self.velocity.normalize().multiple(self.wanderDistance))
        
        return desiredVelocity.subtract(self.velocity).cutTo(self.max_speed).multiple(self.mass).cutTo(self.max_force)
   
   
    def setWanderRadius (self, radius):
        self.wanderRadius = radius
        self.targetCircle = self.velocity.normalize().multiple(radius/2.0)
        
